package com.webauto.asserts;

import org.testng.Assert;

import com.webauto.log.Log;

/**
 * PS:断言工具类
 * @author lkk
 *
 */
public class assertUtil extends Assert{
	/**
	 * PS:是否包含断言信息
	 * @param target
	 * @param asserts
	 * @throws assertException 
	 */
	public static boolean check(String target,String assertion){
		boolean flag = target.contains(assertion);
		if(flag==true) {
			Log.info("+++包含断言通过,检测断言测试部分包含断言["+assertion+"]+++");
		}else {
			flag = false;
			throw new AssertionError("+++包含断言失败,检测断言测试部分["+target+"]未包含断言["+assertion+"]+++");
		}
		return flag;
	}
	/**
	 * PS:是否等于断言信息
	 * @param target
	 * @param asserts
	 * @throws assertException
	 */
	public static boolean equals(String target,String assertion) {
		boolean flag = assertion.equals(target);
		if(flag == true) {
			Log.info("+++比较断言通过,检测断言测试部分等于断言["+assertion+"]+++");
		}else {
			flag = false;
			throw new AssertionError("+++比较断言失败,检测断言测试部分["+target+"]不等于断言["+assertion+"]+++");
		}
		return flag;
	}
	/**
	 * PS:是否匹配正则表达式
	 * @param target
	 * @param asserts
	 * @throws assertException
	 */
	public static boolean matches(String target,String assertionRegex){
		boolean flag = target.matches(assertionRegex);
		if(flag == true) {
			Log.info("+++正则匹配断言通过,检测断言测试部分["+target+"]匹配断言正则表达式["+assertionRegex+"]+++");
		}else {
			flag = false;
			throw new AssertionError("+++正则匹配断言未通过,检测断言测试部分["+target+"]不匹配断言正则表达式["+assertionRegex+"]+++");
		}
		return flag;

	}
	/**
	 * PS:开头匹配断言
	 * @param target
	 * @param assertion
	 * @throws assertException
	 */
	public static boolean startsWith(String target,String assertion){
		boolean flag = target.startsWith(assertion);
		if(flag == true) {
			Log.info("+++检测开头断言通过,检测断言测试部分["+target+"]的头部是断言["+assertion+"]+++");
		}else {
			flag = false;
			throw new AssertionError("+++检测开头断言未通过,检测断言测试部分["+target+"]的头部不是断言["+assertion+"]+++");
		}
		return flag;

	}
	/**
	 * PS:结尾匹配断言
	 * @param target
	 * @param assertion
	 * @throws assertException
	 */
	public static boolean endsWith(String target,String assertion){
		boolean flag = target.endsWith(assertion);
		if(flag == true) {
			Log.info("+++检测结尾断言通过,检测断言测试部分["+target+"]的结尾是断言["+assertion+"]+++");
		}else {
			flag = false;
			throw new AssertionError("+++检测结尾断言未通过,检测断言测试部分["+target+"]的结尾不是断言["+assertion+"]+++");
		}
		return flag;

	}


}
